/*
 * $Id$
 */
package py.firefly.request;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletResponse;
import py.firefly.FireflyException;

/**
 *
 * @author myang
 */
public class HttpResponse implements Response {
    /**
     * 
     */
    private HttpServletResponse _resp;

    /**
     * 
     * @param resp 
     */
    public HttpResponse(final HttpServletResponse resp) {
        _resp = resp;
    } 

    @Override
    public HttpServletResponse containerResponse() {
        return _resp;
    }

    @Override
    public void println(String s) {
        try {
            _resp.getWriter().println(s);
        } catch (final IOException ex) {
        }
    }

    /**
     * 
     * @param name
     * @param val
     * @return 
     */
    @Override
    public HttpResponse header(final String name, final String val) {
        _resp.setHeader(name, val);
        return this;
    }

    /**
     * 
     * @param contentType
     * @return 
     */
    @Override
    public HttpResponse contentType(final String contentType) {
        return header("Content-Type", contentType);
    }

    /**
     * 
     * @param s
     * @return 
     */
    @Override
    public HttpResponse streamOut(final String s) {
        try {
            _resp.getOutputStream().println(s);
        } catch (final IOException ex) {
            throw new FireflyException(ex);
        }
        return this;
    }
}
